<?php
namespace App\Http\Controllers\Xcx\Ywmall;

use App\Service\Xcx\Ywmall\FworderService;
use Illuminate\Http\Request;

class FworderController extends BaseController
{
    //服务订单

    //列表
    public function index(Request $request)
    {
        $pages['start'] = $request->post('page', 1);
        $pages['limit'] = $request->post('size', 2);
        $pas['uid'] = $request->post('uid', 0);
        if (!$pas['uid']) {
            return $this->toJson(-2, '没有登录');
        }
        $res = FworderService::index($pages, $pas);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //添加
    public function add(Request $request)
    {
        $id = $request->post('id', 0);
        $uid = $request->post('uid', 0);
        if (!$id) {
            return $this->toJson(-2, '商品必须的');
        }
        if (!$uid) {
            return $this->toJson(-2, '用户必须的');
        }
        $res = FworderService::add($id, $uid);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }

    //删除
    public function del(Request $request)
    {
        $id = $request->post('id', 0);
        if (!$id) {
            return $this->toJson(-2, '订单必须的');
        }
        $res = FworderService::del($id);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }
}